package com.dongxing.concyrrency.chapter6;

import java.util.concurrent.TimeUnit;

/**
 * 打个标识，代表线程中断，结束
 *
 * @author XavierDong
 **/
public class ThreadCloseGraceful {

    private static class Wroker extends Thread {

        private volatile boolean start = true;

        @Override
        public void run() {
            while (start) {
                //
            }
        }

        public void shutdown() {
            this.start = false;
        }
    }


    public static void main(String[] args) {
        Wroker wroker = new Wroker();
        wroker.start();

        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        wroker.shutdown();
    }

}
